import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/modules/state/getxcontroller/getxcontroller_controller.dart';

class GetxControllerPage extends GetView {

  @override
  Widget build(BuildContext context) {
    // 引入控制器
    // final GetxControllerController controller = new GetxControllerController();
    final GetxControllerController controller = Get.put(GetxControllerController());

    return Scaffold(
      appBar: AppBar(title: Text('GetxController')),

      body: SafeArea(
        child: ListView(
          children: [
            Text(
              '- GetxController 集中管理状态数据',
              style: Theme.of(context).textTheme.headline5
            ),
            Divider(),
            // 在 Obx 回调函数中的内容，才能实时更新
            Obx(() => Text(
              'count: '+controller.count.toString(),
              style: Theme.of(context).textTheme.headline4
            )),
            Text(
              'count: '+controller.count.toString(),
              style: Theme.of(context).textTheme.headline4
            ),
            ElevatedButton(
              onPressed: () {
                controller.increment();
              }, 
              child: Icon(Icons.add)
            ),
            ElevatedButton(
              onPressed: () {
                controller.decrement();
              }, 
              child: Icon(Icons.remove)
            )
          ],
        )
      )
    );
  }
}